/*
 * Project Name spring-boot-tools
 * File Name ExpandableData
 * Package Name com.huxiaosu.tools.common.base.extra
 * Create Time 2024/7/11
 * Create by name：liujie
 */
package com.huxiaosu.tools.common.base.extra;

import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;

import java.util.HashMap;
import java.util.Map;

/**
 * Description
 *
 * @author liujie
 * @date 2024/7/11 17:23
 */
public abstract class AbstractExpandableData implements IExpandableData{
    protected Map<String, Object> extraData;

    @JsonAnyGetter
    @Override
    public Map<String, Object> getExtraData() {
        return extraData;
    }

    @JsonAnySetter
    @Override
    public void setExtraData(Map<String, Object> extraData) {
        this.extraData = extraData;
    }

    @Override
    public void putExtraData(String key, Object data) {
        if (this.extraData == null) {
            extraData = new HashMap<>();
        }
        extraData.put(key, data);
    }

    @Override
    public Object getExtraDataByKey(String key) {
        if (this.extraData == null) {
            return null;
        }
        if (!this.extraData.containsKey(key)) {
            return null;
        }
        return this.extraData.get(key);
    }

    @Override
    public boolean containsExtraDataKey(String key) {
        if (extraData == null) {
            return false;
        }
        return this.extraData.containsKey(key);
    }
}